/**
 * name:        绑定手机号
 * author:      wuwq & lyj
 * Time:        18/01/31
 * Copyright:   chinadangmai.com
 */
function ajax_form(){
    // 判断底部是否定位
    var w_h=$(window).height();
        if(w_h<=920){
            $('.login_foot').css({
                'position': 'inherit',
                'margin-top': '49px'
            })
        }
$('#phoneCode').click(function(){
    //获取倒计时
    var phone = $('#phone').val();
    var url= new_url+"shop/login/sendPhoneCode"; 
    var time='60'
    function tim(){
        setTimeout(function(){                                               
        if(time>'0'){
            tim();
            time --
            $('#phoneCode').hide()
            $('.phoneCode').show()
            // $('.register_bg ul li').eq(1).append('<a class="phoneCode"></a>')
            $('.phoneCode').text(time+'s重新获取');
        }
        else{
            $('.phoneCode').hide()
            $('#phoneCode').show()
            $('#phoneCode').text('重新获取验证码')  
        }    
        },1000)
    }
    if((/^1(3|4|5|7|8)\d{9}$/.test(phone))){
        tim();
        $.ajax({
            type: "post",
            dataType:'json',
            url: url, 
            data:'phone='+phone,       
            success: function(e){ 
                if(e.code=='0'){
                    tc(e.message);  
                }
                else{
                    tc(e.message);
                }
            }
        });
    }
    else{
        tc('请输入手机号')
    }
})
function phone(){    
    var phone = $('#phone').val();  
        if(!(/^1(3|4|5|7|8)\d{9}$/.test(phone))){
            $('#phone').parents('li').addClass('error_bor');
            $('.error_bor').find('.error').show();
            return false;     
        }else{
            $('#phone').parents('li').removeClass('error_bor');
            $('#phone').parents('li').find('.error').hide();
            // return false;
            };    
        if($('#verification').val()==''){
            $('#verification').parents('li').addClass('error_bor'); 
            $('.error_bor').find('.error').show();
            return false; 
        }else{
            $('#verification').parents('li').removeClass('error_bor');
            $('#verification').parents('li').find('.error').hide()
            // return false;
            };           
}
$('#login_sub').on('click',function(){
    phone(); 
    $('.register_bg ul li input').each(function(index,t){
    $(t).blur(function(){
        phone();
    })
})
    if($('.register_bg ul li').hasClass('error_bor')){
        return false;
    }else{
        var phone2 = $('#phone').val();
        var phoneCode=$('#verification').val();
        var oauthId=window.location.href
        var oauthId2=oauthId.split('=')[1]
        var oauthId3= oauthId2.split('&')[0]
        var oauthId4= oauthId2.split('&')[1]
        $.ajax({
        type:'post',
        dataType: 'json',
        data:{isBind:'1',phoneCode:phoneCode,phone:phone2,oauthId:oauthId3},
        url:new_url+'shop/oauth/bindMember',
        success:function(e){ 
            if(e.code=='0'){
                var mycars = new Array()
                    mycars[0] = e.data.name
                    mycars[1] = e.data.nickName
                    mycars[2] = e.data.phone
                    mycars[3] = e.data.avatar
                    mycars[4] = e.data.truename
                    mycars[5] = e.data.memberId
                    mycars[6] = e.data.token
                    mycars[7] = 
                $.cookie('user',mycars,{path:'/'});    
                tc(e.message)
                setTimeout(function(){
                    if($.cookie('this_u')!=''&&$.cookie('this_u')!=null){
                        window.location.href=$.cookie('this_u')
                        $.cookie('this_u','',{path:'/'})
                        return false
                    }
                    else{
                        window.location.href='/index.html'
                    }
                },300)
            }
            else{
                tc(e.message)
            }
        },
    })
    }
    return false;
})

$('.no_binding').click(function(){
    $('.popover_m, .site_bg').fadeIn()
    $('.gb_01, .popover_m , .yes_butt').click(function(){
        $('.popover_m, .site_bg').fadeOut()
    })
    $('.no_butt').click(function(){
        var oauthId=window.location.href
        var oauthId2=oauthId.split('=')[1]
        var oauthId3= oauthId2.split('&')[0]
        var oauthId4= oauthId2.split('&')[1]
        $.ajax({
            type:'post',
            dataType: 'json',
            data:{isBind:'0',oauthId:oauthId3},
            url:new_url+'shop/oauth/bindMember',
            success:function(e){ 
                var mycars = new Array()
                    mycars[0] = e.data.name
                    mycars[1] = e.data.nickName
                    mycars[2] = e.data.phone
                    mycars[3] = e.data.avatar
                    mycars[4] = e.data.truename
                    mycars[5] = e.data.memberId
                    mycars[6] = e.data.token
                    mycars[7] = 
                $.cookie('user',mycars,{path:'/'}); 
                if(e.code=='0'){
                    tc(e.message)
                        if($.cookie('this_u')!=''&&$.cookie('this_u')!=null){
                            window.location.href=$.cookie('this_u')
                            $.cookie('this_u','',{path:'/'})
                            return false
                        }
                        else{
                            window.location.href='/index.html'
                        }
                }
            }
        })
    })
})
}